/**
* 作者: lichuan
* 日期: 2025-07-28 15:02:50
* 备注: 联盟总动员玩家数据
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserMobileInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserMobileInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 玩家id
	protected int acceptNum; // 普通任务完成次数
	protected int highAcceptNum; // 高级任务完成次数
	protected int taskId; // 当前进行中的任务
	protected String unionRewardInfo = ""; // 联盟里程联盟奖励领取
	protected String rewardInfo = ""; // 联盟里程个人奖励领取
	protected int buyNum; // 购买次数
	protected long resetTime; // 重置时间
	protected int singleRankReward; // 是否领取个人排行榜奖励
	protected int unionRankReward; // 是否领取联盟排行榜奖励
	protected int totalAcceptNum; // 接取任务总次数
	protected int taskType; // 当前进行任务的类型
	protected long score; // 积分

	public void reset() {
	}

	protected String getKey() {
		return "UserMobileInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_mobile_info"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入库
	*/
	public JsonObject updateNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE_NOW, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 玩家id
		obj.put("acceptNum", acceptNum); // 普通任务完成次数
		obj.put("highAcceptNum", highAcceptNum); // 高级任务完成次数
		obj.put("taskId", taskId); // 当前进行中的任务
		obj.put("unionRewardInfo", unionRewardInfo); // 联盟里程联盟奖励领取
		obj.put("rewardInfo", rewardInfo); // 联盟里程个人奖励领取
		obj.put("buyNum", buyNum); // 购买次数
		obj.put("resetTime", resetTime); // 重置时间
		obj.put("singleRankReward", singleRankReward); // 是否领取个人排行榜奖励
		obj.put("unionRankReward", unionRankReward); // 是否领取联盟排行榜奖励
		obj.put("totalAcceptNum", totalAcceptNum); // 接取任务总次数
		obj.put("taskType", taskType); // 当前进行任务的类型
		obj.put("score", score); // 积分
		return obj;
	}

	public PBUserMobileInfo.Builder takeInitBuilder() {
		PBUserMobileInfo.Builder sb = PBUserMobileInfo.newBuilder();
		if (acceptNum != 0) {
			sb.setAcceptNum(acceptNum);
		}
		if (highAcceptNum != 0) {
			sb.setHighAcceptNum(highAcceptNum);
		}
		if (taskId != 0) {
			sb.setTaskId(taskId);
		}
		if (this.unionRewardInfo != null && this.unionRewardInfo.length() > 0) {
			JsonArray list = new JsonArray(this.unionRewardInfo);
			for(int i=0; i<list.size(); i++) {
				sb.addUnionRewardInfo(list.getInteger(i));
			}
		}
		if (this.rewardInfo != null && this.rewardInfo.length() > 0) {
			JsonArray list = new JsonArray(this.rewardInfo);
			for(int i=0; i<list.size(); i++) {
				sb.addRewardInfo(list.getInteger(i));
			}
		}
		if (buyNum != 0) {
			sb.setBuyNum(buyNum);
		}
		if (singleRankReward != 0) {
			sb.setSingleRankReward(singleRankReward);
		}
		if (unionRankReward != 0) {
			sb.setUnionRankReward(unionRankReward);
		}
		if (totalAcceptNum != 0) {
			sb.setTotalAcceptNum(totalAcceptNum);
		}
		if (taskType != 0) {
			sb.setTaskType(taskType);
		}
		if (score != 0) {
			sb.setScore(score);
		}
		return sb;
	}

	public PBUserMobileInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserMobileInfo.Builder sb = PBUserMobileInfo.newBuilder();
		if (isFieldUpdate("acceptNum")) {
			sb.setAcceptNum(acceptNum);
		}
		if (isFieldUpdate("highAcceptNum")) {
			sb.setHighAcceptNum(highAcceptNum);
		}
		if (isFieldUpdate("taskId")) {
			sb.setTaskId(taskId);
		}
		if (isFieldUpdate("unionRewardInfo")) {
			if (this.unionRewardInfo != null && this.unionRewardInfo.length() > 0) {
				JsonArray list = new JsonArray(this.unionRewardInfo);
				for(int i=0; i<list.size(); i++) {
					sb.addUnionRewardInfo(list.getInteger(i));
				}
				if (list.isEmpty()) {
					sb.clearUnionRewardInfo();
				}
			} else {
				sb.clearUnionRewardInfo();
			}
		}
		if (isFieldUpdate("rewardInfo")) {
			if (this.rewardInfo != null && this.rewardInfo.length() > 0) {
				JsonArray list = new JsonArray(this.rewardInfo);
				for(int i=0; i<list.size(); i++) {
					sb.addRewardInfo(list.getInteger(i));
				}
				if (list.isEmpty()) {
					sb.clearRewardInfo();
				}
			} else {
				sb.clearRewardInfo();
			}
		}
		if (isFieldUpdate("buyNum")) {
			sb.setBuyNum(buyNum);
		}
		if (isFieldUpdate("singleRankReward")) {
			sb.setSingleRankReward(singleRankReward);
		}
		if (isFieldUpdate("unionRankReward")) {
			sb.setUnionRankReward(unionRankReward);
		}
		if (isFieldUpdate("totalAcceptNum")) {
			sb.setTotalAcceptNum(totalAcceptNum);
		}
		if (isFieldUpdate("taskType")) {
			sb.setTaskType(taskType);
		}
		if (isFieldUpdate("score")) {
			sb.setScore(score);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public int getAcceptNum() {
		return acceptNum;
	}

	public void putAcceptNum(int acceptNum) {
		if (this.acceptNum != acceptNum) {
			this.acceptNum = acceptNum;
			updateRedisHashField(getKey(), "acceptNum", this.acceptNum);
		}
	}

	public void addAcceptNum(int value) {
		this.acceptNum += value;
		updateRedisHashField(getKey(), "acceptNum", this.acceptNum);
	}

	public int getHighAcceptNum() {
		return highAcceptNum;
	}

	public void putHighAcceptNum(int highAcceptNum) {
		if (this.highAcceptNum != highAcceptNum) {
			this.highAcceptNum = highAcceptNum;
			updateRedisHashField(getKey(), "highAcceptNum", this.highAcceptNum);
		}
	}

	public void addHighAcceptNum(int value) {
		this.highAcceptNum += value;
		updateRedisHashField(getKey(), "highAcceptNum", this.highAcceptNum);
	}

	public int getTaskId() {
		return taskId;
	}

	public void putTaskId(int taskId) {
		if (this.taskId != taskId) {
			this.taskId = taskId;
			updateRedisHashField(getKey(), "taskId", this.taskId);
		}
	}

	public void addTaskId(int value) {
		this.taskId += value;
		updateRedisHashField(getKey(), "taskId", this.taskId);
	}

	public JsonArray getUnionRewardInfoArray() {
		if (this.unionRewardInfo != null && this.unionRewardInfo.length() > 0) {
			return new JsonArray(this.unionRewardInfo);
		} else {
			return new JsonArray();
		}
	}

	public String getUnionRewardInfo() {
		return unionRewardInfo;
	}

	public void putUnionRewardInfo(String unionRewardInfo) {
		if (!this.unionRewardInfo.equals(unionRewardInfo)) {
			this.unionRewardInfo = unionRewardInfo;
			updateRedisHashField(getKey(), "unionRewardInfo", this.unionRewardInfo);
		}
	}

	public JsonArray getRewardInfoArray() {
		if (this.rewardInfo != null && this.rewardInfo.length() > 0) {
			return new JsonArray(this.rewardInfo);
		} else {
			return new JsonArray();
		}
	}

	public String getRewardInfo() {
		return rewardInfo;
	}

	public void putRewardInfo(String rewardInfo) {
		if (!this.rewardInfo.equals(rewardInfo)) {
			this.rewardInfo = rewardInfo;
			updateRedisHashField(getKey(), "rewardInfo", this.rewardInfo);
		}
	}

	public int getBuyNum() {
		return buyNum;
	}

	public void putBuyNum(int buyNum) {
		if (this.buyNum != buyNum) {
			this.buyNum = buyNum;
			updateRedisHashField(getKey(), "buyNum", this.buyNum);
		}
	}

	public void addBuyNum(int value) {
		this.buyNum += value;
		updateRedisHashField(getKey(), "buyNum", this.buyNum);
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

	public int getSingleRankReward() {
		return singleRankReward;
	}

	public void putSingleRankReward(int singleRankReward) {
		if (this.singleRankReward != singleRankReward) {
			this.singleRankReward = singleRankReward;
			updateRedisHashField(getKey(), "singleRankReward", this.singleRankReward);
		}
	}

	public void addSingleRankReward(int value) {
		this.singleRankReward += value;
		updateRedisHashField(getKey(), "singleRankReward", this.singleRankReward);
	}

	public int getUnionRankReward() {
		return unionRankReward;
	}

	public void putUnionRankReward(int unionRankReward) {
		if (this.unionRankReward != unionRankReward) {
			this.unionRankReward = unionRankReward;
			updateRedisHashField(getKey(), "unionRankReward", this.unionRankReward);
		}
	}

	public void addUnionRankReward(int value) {
		this.unionRankReward += value;
		updateRedisHashField(getKey(), "unionRankReward", this.unionRankReward);
	}

	public int getTotalAcceptNum() {
		return totalAcceptNum;
	}

	public void putTotalAcceptNum(int totalAcceptNum) {
		if (this.totalAcceptNum != totalAcceptNum) {
			this.totalAcceptNum = totalAcceptNum;
			updateRedisHashField(getKey(), "totalAcceptNum", this.totalAcceptNum);
		}
	}

	public void addTotalAcceptNum(int value) {
		this.totalAcceptNum += value;
		updateRedisHashField(getKey(), "totalAcceptNum", this.totalAcceptNum);
	}

	public int getTaskType() {
		return taskType;
	}

	public void putTaskType(int taskType) {
		if (this.taskType != taskType) {
			this.taskType = taskType;
			updateRedisHashField(getKey(), "taskType", this.taskType);
		}
	}

	public void addTaskType(int value) {
		this.taskType += value;
		updateRedisHashField(getKey(), "taskType", this.taskType);
	}

	public long getScore() {
		return score;
	}

	public void putScore(long score) {
		if (this.score != score) {
			this.score = score;
			updateRedisHashField(getKey(), "score", this.score);
		}
	}

	public void addScore(long value) {
		this.score += value;
		updateRedisHashField(getKey(), "score", this.score);
	}

}